package vip.xumy.admin.sys.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import vip.xumy.admin.sys.pojo.Dictionary;
import vip.xumy.admin.sys.service.DictionaryService;
import vip.xumy.core.exception.CoreException;
import vip.xumy.core.pojo.com.AjaxResponse;
import vip.xumy.core.pojo.com.PageResponse;

/**
 * @author:mengyxu
 * @date:2019年12月6日
 */

@RestController
@RequestMapping("dict")
public class DictionaryController {
	@Autowired
	private DictionaryService distService;

	@RequestMapping(value = "list", method = RequestMethod.GET)
	public PageResponse<Dictionary> queryDistList(Dictionary example) {
		Page<Dictionary> pages = PageHelper.startPage(example.getPage(), example.getSize());
		List<Dictionary> list = distService.queryType(example);
		PageResponse<Dictionary> rsp = new PageResponse<>();
		rsp.setRows(list);
		rsp.setTotal(pages.getTotal());
		return rsp;
	}

	@RequestMapping(value = "save", method = RequestMethod.POST)
	public AjaxResponse saveDistionary(@RequestBody Dictionary dist) {
		distService.save(dist);
		return new AjaxResponse(true, "添加数据字典成功");
	}

	@RequestMapping(value = "update", method = RequestMethod.POST)
	public AjaxResponse updateDistionary(@RequestBody Dictionary dist) {
		distService.update(dist);
		return new AjaxResponse(true, "修改数据字典成功");
	}

	@RequestMapping(value = "delete", method = RequestMethod.POST)
	public AjaxResponse deleteDistionary(@RequestBody Dictionary dist) throws CoreException {
		distService.delete(dist);
		return new AjaxResponse(true, "删除数据字典成功");
	}

}
